package com.dehui.traders.ui.trend;

import android.support.v4.content.ContextCompat;

import com.dehui.traders.BR;
import com.dehui.traders.R;
import com.dehui.traders.databinding.FragmentTrendBinding;
import com.dehui.traders.ui.base.AppFragment;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hqq on 18.3.30.
 */

public class TrendFragment extends AppFragment<FragmentTrendBinding,TrendViewModel> {

    @Override
    public int initContentView() {
        return R.layout.fragment_trend;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public TrendViewModel initViewModel() {
        return new TrendViewModel(getContext(),this);
    }

    @Override
    public void initData() {
        super.initData();
        initViews();
        initToolbarValue(R.string.trend);
    }


    private void initViews() {
        binding.refreshView.setRefreshHeader(new ClassicsHeader(getActivity()));
        binding.refreshView.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                viewModel.initTrend();
            }
        });
    }

    public void initRingView(String probability, String trend) {
        List<Integer> colorList = new ArrayList<>();
        if ("上涨".equals(trend)){
            colorList.add(R.color.red);
        }else{
            colorList.add(R.color.green);
        }
        colorList.add(R.color.gray);
        List<Float> rateList = new ArrayList<>();
        rateList.add(Float.valueOf(probability));
        rateList.add(100 - Float.valueOf(probability));
        binding.ringview.setShow(colorList, rateList,true,true);
        binding.ringview.invalidate();
    }

    public void onComplete() {
        binding.refreshView.finishRefresh();
    }
}
